package com.kun.framework.core.exception;

import cn.hutool.core.util.StrUtil;
import com.kun.framework.core.enums.PopupMessageTypeEnum;
import javafx.stage.Stage;

/**
 * 弹出窗口
 *
 * @author gzc
 * @since 2024/9/3
 **/
public abstract class AbstractPopupException extends RuntimeException {
    /**
     * 信息
     */
    private final String msg;
    /**
     * 延迟关闭时间，毫秒
     */
    private final long timed;
    /**
     * 顶层窗口对象
     */
    private final Stage initOwnerStage;
    /**
     * 设置弹窗信息类型枚举
     *
     * @return 弹窗信息类型枚举
     */
    protected abstract PopupMessageTypeEnum getPopupMessageTypeEnum();

    public AbstractPopupException(String message) {
        this(1000L, message);
    }

    public AbstractPopupException(long timed, String message) {
        this(timed, null, message);
    }

    public AbstractPopupException(long timed, String message, Stage initOwnerStage) {
        this(timed, initOwnerStage, message);
    }

    public AbstractPopupException(long timed, Stage initOwnerStage, String message, Object... params) {
        this.timed = timed;
        this.initOwnerStage = initOwnerStage;
        this.msg = StrUtil.format(message, params);
        // 赋值当前线程的堆栈信息，可获取到抛出该异常的具体代码位置
        setStackTrace(Thread.currentThread().getStackTrace());
    }

    public String getMsg() {
        return this.msg;
    }

    public long getTimed() {
        return this.timed;
    }

    public Stage getInitOwnerStage() {
        return this.initOwnerStage;
    }

}
